/*
  Name: DeadProxyNetworkHandler.h
  Copyright:
  Author: Carl Chatfield
  Date: 20/01/08 13:26
  Description: Manages network events for each client
*/

#ifndef __DEADPROXYCLIENTNETWORKHANDLER_h__
#define __DEADPROXYCLIENTNETWORKHANDLER_h__

#ifdef __BORLANDC__
	#pragma hdrstop
#endif

#ifndef WX_PRECOMP
	#include <wx/wx.h>
#else
	#include <wx/wxprec.h>
#endif

#include "windows.h"
#include "winsock.h"
#include "DeadProxyClientEvent.h"
#include "DeadProxyPacketBuffer.h"
#include "DeadProxyPacketQueue.h"
class ClientNetworkHandler
{
    private:
        void * pClient;
        
        SOCKET ToClientSocket;
        SOCKET ToServerSocket;
        unsigned char ToClientRawBuffer[65536]; //data is initially written here
        unsigned char ToServerRawBuffer[65536];
        PacketBuffer * ToClientBufferSend; //Name is kinda deciving, ToClientBuffer recvs from ToClientSocket
        PacketBuffer * ToServerBufferSend;
        PacketBuffer * ToClientBufferRecv;
        PacketBuffer * ToServerBufferRecv;
        bool ToClientCanSend;
        bool ToServerCanSend;
        PacketQueue * ToClientPacketQueue;
        PacketQueue * ToServerPacketQueue;
        int LoginOrGame; //0 for login, 1 for game
        
        
        void WriteToSocket(SOCKET s);
    public:
        int OnAccept(ClientEvent * evt);
        int OnConnect(ClientEvent * evt);
        int OnRead(ClientEvent * evt);
        int OnWrite(ClientEvent * evt);
        int OnClose(ClientEvent * evt);
        void Message(ClientEvent * evt);
        
        void SendToServer(PacketBuffer * packet);
        void SendToClient(PacketBuffer * packet);
        ClientNetworkHandler(void* ptrClient);
        virtual ~ClientNetworkHandler();
};

#endif
